<template>
    <div>
  <h1>会员权益添加</h1>
  <table class="atble table-bordered" border="1">
    <tr>
        <td>权益名称</td>
        <td><input type="text" v-model="ad.mr_name" placeholder="请输入权益名称"></td>
    </tr>

    <tr>
        <td>权益说明</td>
        <td><textarea placeholder="请输入权益说明" v-model="ad.mr_sm"></textarea></td>
    </tr>

    <tr>
        <td>是否自定义</td>
        <td><input type="radio" v-model="ad.mr_zdy" :value="true" >是
            <input type="radio" v-model="ad.mr_zdy" :value="false" >否
        </td>
    </tr>

    <tr>
        <td>规则类型</td>
        <td><input type="radio" v-model="ad.mr_meiju" :value="0" >折扣
            <input type="radio" v-model="ad.mr_meiju" :value="1" >餐饮
            <input type="radio" v-model="ad.mr_meiju" :value="2" >延时
        </td>
    </tr>

    <tr>
        <td>权益规则</td>
        <td><textarea  placeholder="请输入权益规则" v-model="ad.mr_Rule"></textarea></td>
    </tr>

    <tr>
        <td></td>
        <td><input type="button" value="注册" @click="pd"></td>
    </tr>
  </table>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';


const ad=ref({

    mr_id: 0,
  mr_name: "",
  mr_sm: "",
  mr_zdy: true,
  mr_meiju: 0,
  mr_Rule: ""

})


const pd=()=>{

    
if(ad.value.mr_name=="")
{
alert('权益名称不能为空');
return;

}

if(ad.value.mr_Rule.length<6)
{
alert('权益规则不能小于6个字');
return;

}

axios.post('https://localhost:7268/api/hy/addhyqyi',ad.value)
.then(res=>{
    if(res.data==-1)
{
alert('该权益名称已被注册,请更换名称');
return;

}
if(res.data>0)
{
alert('注册成功')

}
else{

    alert('注册失败') 
}

})
.catch(error=>{

console.log(error)

})

}


</script>

<style scoped>

</style>